package acom.test.swing.aa;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;


public class SystemUtil {

	private static List<AnswerPeople> peoples = new ArrayList<AnswerPeople>();
	private static List<Prize> prizes = new ArrayList<Prize>();
	
	private static Prize curPrize; 
	
	public static void showInCenter(JFrame frame) {
		// 显示位置
		int HEIGHT = frame.getHeight();
		int WIDTH = frame.getWidth();
		Toolkit kit = Toolkit.getDefaultToolkit();// 设置顶层容器框架为居中
		Dimension screenSize = kit.getScreenSize();
		int width = screenSize.width;
		int height = screenSize.height;
		int x = (width - WIDTH) / 2;
		int y = (height - HEIGHT) / 2;
		frame.setLocation(x, y);
	}
	
	public static boolean isInteger(String sum){
		String num_regex = "^[0-9]+$";				
		return sum.matches(num_regex);
	}
	
	public static List<AnswerPeople> getPeoplelist(){
		return peoples;
	}
	public static void setPeoplelist(List<AnswerPeople> peoplelist){
		peoples = peoplelist;
	}
	
	public static List<Prize> getPrizelist(){
		return prizes;
	}

	public static Prize getCurPrize() {
		return curPrize;
	}

	public static void setCurPrize(Prize prize) {
		SystemUtil.curPrize = prize;
	}

	public static Prize findPrizeByName(String prizeName) {
		
		for(Prize prize:prizes){			
			if(prizeName.equals(prize.getPname())){
				return prize;
			}			
		}
		
		return null;
	}
}
